
package com.rs.controller.Rs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rs.model.Adjustment;
import com.rs.model.Attendance;
import com.rs.model.AttendanceRules;
import com.rs.model.Bonus;
import com.rs.model.Department;
import com.rs.model.Position;
import com.rs.model.Resign;
import com.rs.model.rs.User;
import com.rs.service.rs.DepartmentService;
import com.rs.util.ImagePanel;
import com.rs.util.SpringContextUtils;

public class Administration extends JFrame {

	private DepartmentService dts = SpringContextUtils.getBean(DepartmentService.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JDesktopPane desktopPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					//Administration frame = new Administration();
					//frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Administration(final User user) {
		setResizable(false);
		setTitle("融盛科技公司管理系统");
		setIconImage(Toolkit.getDefaultToolkit().getImage(Administration.class.getResource("/images/rongsheng.png")));
		System.out.println(Administration.class.getResource("/images/rongsheng.png"));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setBounds(200, 50, 902, 693);

		desktopPane = new JDesktopPane();
		desktopPane.setBackground(new Color(0, 0, 0));
		setContentPane(desktopPane);
		//设置背景图
		final ImagePanel imagePanel = new ImagePanel(902, 693, "time4.jpg");
		imagePanel.setLayout(new BorderLayout(0, 0));
		setContentPane(imagePanel);

		//导航栏
		JMenuBar menuBar_1 = new JMenuBar();
		setJMenuBar(menuBar_1);

		JMenu men_user = new JMenu("员工管理");
		menuBar_1.add(men_user);
		men_user.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_user.setBackground(Color.WHITE);
		men_user.setIcon(new ImageIcon(Administration.class.getResource("/images/renyuan.png")));
		String type = null;
		for (int i = 0; i < 2; i++) {
			switch (i) {
			case 0:
				type = "新增员工";
				break;
			case 1:
				type = "查询员工";
				break;
			}
			final JMenuItem menuItem = new JMenuItem(type);
			menuItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					String menuTxt = menuItem.getText();
					switch (menuTxt) {
					case "新增员工":
						//打开一个新的页面	
						JDesktopPane Add = new JDesktopPane();
						//设置控件是否透明
						Add.setOpaque(false);
						imagePanel.add(Add, BorderLayout.CENTER);
						Add.add(new UserJFrame().new AddUser());
						break;
					case "查询员工":
						//打开一个新的页面	
						JDesktopPane query = new JDesktopPane();
						//设置控件是否透明
						query.setOpaque(false);
						imagePanel.add(query, BorderLayout.CENTER);
						query.add(new UserJFrame().new QueryUser(query));
						break;

					}
				}
			});
			men_user.add(menuItem);
		}

		JMenu men_bumen = new JMenu("部门管理");
		menuBar_1.add(men_bumen);
		men_bumen.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_bumen.setBackground(Color.WHITE);
		men_bumen.setIcon(new ImageIcon(Administration.class.getResource("/images/bumen.png")));
		
		
		
		JMenuItem bumen = new JMenuItem("新增部门");
		men_bumen.add(bumen);		 
		bumen.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new BumenJFrame().new AddBumen().setVisible(true);
			  }
			});
		
		JMenuItem bumen1 = new JMenuItem("部门列表");
		men_bumen.add(bumen1);
		bumen1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				List<Department> ll = dts.selBuMenAll();
				new BumenJFrame().new SelBumen(ll).setVisible(true);
			  }
			});
		
	

		JMenu men_zhiwu = new JMenu("职务管理");
		menuBar_1.add(men_zhiwu);
		men_zhiwu.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_zhiwu.setBackground(Color.WHITE);
		men_zhiwu.setIcon(new ImageIcon(Administration.class.getResource("/images/zhiwu.png")));
		
		JMenuItem zhiwu = new JMenuItem("新增职务");
		men_zhiwu.add(zhiwu);		 
		zhiwu.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				List<Department> ll = dts.selBuMenAll();
				new ZhiwuJFrame().new AddZhiwu(ll).setVisible(true);
			  }
			});

		JMenuItem zhiwu1 = new JMenuItem("职务列表");
		men_zhiwu.add(zhiwu1);		 
		zhiwu1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				List<Position> ll = dts.positionSelectAll();
				new ZhiwuJFrame().new SelZhiwu(ll).setVisible(true);
			  }
			});
		
		JMenu men_kaoqing = new JMenu("考勤管理");
		menuBar_1.add(men_kaoqing);
		men_kaoqing.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_kaoqing.setBackground(Color.WHITE);
		men_kaoqing.setIcon(new ImageIcon(Administration.class.getResource("/images/kaoqin.png")));
		
		JMenuItem kaoqi = new JMenuItem("考勤规则");
		men_kaoqing.add(kaoqi);		 
		kaoqi.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				AttendanceRules att = dts.attendanceRulesFind();
				new DakaJFrame().new SelectRules(att).setVisible(true);
			  }
		});
		
		
		JMenuItem kaoqing = new JMenuItem("考勤记录");
		men_kaoqing.add(kaoqing);		 
		kaoqing.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Page<Attendance> page = PageHelper.startPage(1, 10);
				int yeshu = 1;
				int type = 1;
				int dangtian=0;
				List<Attendance> ll = dts.attendanceSelectByDay();
				Attendance att = new Attendance();
				int pages = page.getPages();
				new DakaJFrame().new SelectByDay(ll,pages,yeshu,dangtian,type,att).setVisible(true);
			  }
		});

		JMenuItem daochu = new JMenuItem("导出考勤记录");
		men_kaoqing.add(daochu);		 
		daochu.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new DakaJFrame().new Daochu().setVisible(true);
			  }
		});

		JMenu men_xiangmu = new JMenu("项目管理");
		menuBar_1.add(men_xiangmu);
		men_xiangmu.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_xiangmu.setBackground(Color.WHITE);
		men_xiangmu.setIcon(new ImageIcon(Administration.class.getResource("/images/liebiao.png")));

		String projectType = null;
		for (int i = 0; i < 2; i++) {
			switch (i) {
			case 0:
				projectType = "查询项目";
				break;

			case 1:
				projectType = "查询文档";
				break;

			}
			final JMenuItem menu_project = new JMenuItem(projectType);
			menu_project.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					switch (menu_project.getText()) {
					case "查询项目":
						JDesktopPane project = new JDesktopPane();
						//设置控件是否透明
						project.setOpaque(false);
						project.add(new ProjectJFrame().new ProJFrame(project));
						imagePanel.add(project, BorderLayout.CENTER);
						break;
					case "查询文档":
						JDesktopPane doucumen = new JDesktopPane();
						//设置控件是否透明
						doucumen.setOpaque(false);
						doucumen.add(new DocumentJFame().new DoucumenLook());
						imagePanel.add(doucumen, BorderLayout.CENTER);
						break;

					}
				}
			});
			men_xiangmu.add(menu_project);
		}

		/***************************/

		JMenu men_xingzheng = new JMenu("行政管理");
		menuBar_1.add(men_xingzheng);
		men_xingzheng.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_xingzheng.setBackground(Color.WHITE);
		men_xingzheng.setIcon(new ImageIcon(Administration.class.getResource("/images/xingzheng.png")));

		JMenu menu4 = new JMenu("发布通知管理");
		men_xingzheng.add(menu4);

		String tongzhi = null;
		for (int i = 0; i < 2; i++) {
			switch (i) {
			case 0:
				tongzhi = "发布通知";
				break;

			case 1:
				tongzhi = "查询通知";
				break;

			}
			final JMenuItem menu_tonfzhi = new JMenuItem(tongzhi);
			menu_tonfzhi.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					switch (menu_tonfzhi.getText()) {
					case "发布通知":
						JDesktopPane project = new JDesktopPane();
						//设置控件是否透明
						project.setOpaque(false);
						project.add(new NoticeJFame().new AddNotice());
						imagePanel.add(project, BorderLayout.CENTER);
						break;
					case "查询通知":
						JDesktopPane doucumen = new JDesktopPane();
						//设置控件是否透明
						doucumen.setOpaque(false);
						doucumen.add(new NoticeJFame().new QueryNotice(doucumen));
						imagePanel.add(doucumen, BorderLayout.CENTER);
						break;

					}
				}
			});
			menu4.add(menu_tonfzhi);
		}

		JMenu menu5 = new JMenu("物品领用管理");
		men_xingzheng.add(menu5);

		JMenuItem menu_wupin = new JMenuItem("查询领用");
		menu_wupin.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				JDesktopPane doucumen = new JDesktopPane();
				//设置控件是否透明
				doucumen.setOpaque(false);
				doucumen.add(new ItemsJFame().new QueryItems(doucumen, user));
				imagePanel.add(doucumen, BorderLayout.CENTER);

			}
		});

		menu5.add(menu_wupin);

		JMenu menu6 = new JMenu("报销申请管理");
		men_xingzheng.add(menu6);
		String baoxiao = null;
		for (int i = 0; i < 3; i++) {
			switch (i) {
			case 0:
				baoxiao = "添加报销类别";
				break;
			case 1:
				baoxiao = "查询报销类别";
				break;
			case 2:
				baoxiao = "查询报销申请详细";
				break;

			}
			final JMenuItem menu_tonfzhi = new JMenuItem(baoxiao);
			menu_tonfzhi.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					switch (menu_tonfzhi.getText()) {
					case "添加报销类别":
						JDesktopPane jp1 = new JDesktopPane();
						//设置控件是否透明
						jp1.setOpaque(false);
						jp1.add(new ReimTypeJFame().new AddReimType());
						imagePanel.add(jp1, BorderLayout.CENTER);
						break;
					case "查询报销类别":
						JDesktopPane jp2 = new JDesktopPane();
						//设置控件是否透明
						jp2.setOpaque(false);
						jp2.add(new ReimTypeJFame().new LookReim(jp2));
						imagePanel.add(jp2, BorderLayout.CENTER);
						break;
					case "查询报销申请详细":
						JDesktopPane jp3 = new JDesktopPane();
						//设置控件是否透明
						jp3.setOpaque(false);
						jp3.add(new ReimJFame().new selectJFame(jp3, user));
						imagePanel.add(jp3, BorderLayout.CENTER);
						break;

					}
				}
			});
			menu6.add(menu_tonfzhi);
		}

		JMenu men_hr = new JMenu("人事管理");       
		menuBar_1.add(men_hr);
		men_hr.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		men_hr.setBackground(Color.WHITE);
		men_hr.setIcon(new ImageIcon(Administration.class.getResource("/images/renshi.png")));
		
		JMenuItem tiaozheng = new JMenuItem("职位调整申请记录");
		men_hr.add(tiaozheng);		 
		tiaozheng.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Page<Adjustment> page = PageHelper.startPage(1, 10);
				int yeshu = 1;
				int type = 1;
				List<Adjustment> ll = dts.adjustmentSelectAll();
				Adjustment adj = new Adjustment();
				int pages = page.getPages();
				new HRJFrame().new SelectAll(ll,pages,yeshu,type,adj).setVisible(true);
			  }
		});
		
		JMenuItem lizhi = new JMenuItem("离职申请记录");
		men_hr.add(lizhi);		 
		lizhi.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Page<Adjustment> page = PageHelper.startPage(1, 10);
				int yeshu = 1;
				int type = 1;
				List<Resign> ll = dts.ResignSelectAll();
				Resign resign = new Resign();
				int pages = page.getPages();
				new HRJFrame().new LzSelectAll(ll,pages,yeshu,type,resign).setVisible(true);
			  }
		});
		
		JMenuItem jiangjin = new JMenuItem("奖金申请记录");
		men_hr.add(jiangjin);		 
		jiangjin.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Page<Bonus> page = PageHelper.startPage(1, 10);
				int yeshu = 1;
				int type = 1;
				List<Bonus> ll = dts.bonusSelectAll();
				Bonus bonus = new Bonus();
				int pages = page.getPages();
				new HRJFrame().new JjSelectAll(ll,pages,yeshu,type,bonus).setVisible(true);
			  }
		});
		

		this.getContentPane().setVisible(true);

	}

}
